home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / HDX_BACK / HDX302.TT / FMT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  5.5 KB  |  260 lines

  1. /* fmt.c */
  2.  
  3.  
  4. #include "obdefs.h"
  5. #include "defs.h"
  6. #include "part.h"
  7. #include "hdx.h"
  8. #include "addr.h"
  9.  
  10.  
  11. extern char sbuf[];
  12. extern int rebootp;
  13.  
  14.  
  15. /*
  16.  * These constants are used in a heuristic that determines
  17.  * if the format parameter information in the boot sector
  18.  * is intact.  (See fmtpok()).
  19.  */
  20. #define    MAXCYLS        4096        /* max number of cylinders */
  21. #define    MINCYLS        100        /* minimum number of cylinders */
  22. #define    MAXHEADS    16        /* max number of heads */
  23. #define    MINHEADS    2        /* minimum number of heads */
  24. #define    MAXLZ        16        /* max landing zone value */
  25. #define    MAXRT        2        /* max step-rate code */
  26.  
  27.  
  28. /*
  29.  * These are the default format parameters;
  30.  * they are for a 20Mb Mutsubuishi drive.
  31.  *
  32.  * If we change drives, this might have to be changed.
  33.  *
  34.  */
  35. HINFO deffmt = {
  36.     0x264,        /* 612 cylinders */
  37.     4,        /* 4 heads */
  38.     0x264,        /* no reduced write-current cylinder */
  39.     0x264,        /* no write precomp cylinder */
  40.     10,        /* landing zone position = 10 */
  41.     2,        /* use buffered seeks */
  42.     1,        /* interleave = 1 */
  43.     17        /* 17 sectors per track */
  44. };
  45.  
  46.  
  47. /*
  48.  * Report format error.
  49.  *
  50.  */
  51. formaterr(dev)
  52. int dev;
  53. {
  54.     char *pdev="X";
  55.     
  56.     *pdev = dev + '0';
  57.     (cantform[FMTDEV].ob_spec)->te_ptext = pdev;
  58.     cantform[FMTERROK].ob_state = NORMAL;
  59.     execform(cantform);
  60.     return ERROR;
  61. }
  62.  
  63.  
  64. /*
  65.  * Set format parameters in a
  66.  * root sector image.
  67.  * 6-13-88  only set size of hard disk.
  68.  *
  69.  */
  70.  
  71. sdisksiz(image, hdsiz)
  72. char *image;
  73. long hdsiz;
  74. {
  75.     ((RSECT *)(image + 0x200 - sizeof(RSECT)))->hd_siz = hdsiz;
  76.  
  77. }
  78.  
  79.  
  80. /*
  81.  * Set format parameters in a
  82.  * root sector image.
  83.  *
  84.  */
  85. sfmtparm(image, fmtparm)
  86. char *image;
  87. HINFO *fmtparm;
  88. {
  89.     register HINFO *rinfo;
  90.     register long siz;
  91.  
  92.     rinfo = &((RSECT *)(image + 0x200 - sizeof(RSECT)))->hd_info;
  93.     rinfo->hi_cc = fmtparm->hi_cc;
  94.     rinfo->hi_dhc = fmtparm->hi_dhc;
  95.     rinfo->hi_rwcc = fmtparm->hi_rwcc;
  96.     rinfo->hi_wpc = fmtparm->hi_wpc;
  97.     rinfo->hi_lz = fmtparm->hi_lz;
  98.     rinfo->hi_rt = fmtparm->hi_rt;
  99.     rinfo->hi_in = fmtparm->hi_in;
  100.     rinfo->hi_spt = fmtparm->hi_spt;
  101.  
  102.     /* Compute total disk size
  103.      * = <#cyls> * <#heads> * <#sectors / track>
  104.      */
  105.     ((RSECT *)(image + 0x200 - sizeof(RSECT)))->hd_siz = 
  106.         (long)fmtparm->hi_cc *
  107.         (long)fmtparm->hi_dhc *
  108.         (long)fmtparm->hi_spt; 
  109.  
  110. }
  111.  
  112.  
  113. /*
  114.  * Determine if format parameters are good;
  115.  * return OK if they appear to be,
  116.  * ERROR if they don't appear to be.
  117.  *
  118.  */
  119. fmtpok(fmtparm)
  120. HINFO *fmtparm;
  121. {
  122.     if (fmtparm->hi_cc > MAXCYLS ||
  123.     fmtparm->hi_cc < MINCYLS ||
  124.     fmtparm->hi_dhc > MAXHEADS ||
  125.     fmtparm->hi_dhc < MINHEADS ||
  126.     fmtparm->hi_lz > MAXLZ ||
  127.     fmtparm->hi_rt > MAXRT)
  128.         return ERROR;
  129.  
  130.     return OK;
  131. }
  132.  
  133.  
  134. /*
  135.  * Setup default format parameters in hinfo;
  136.  * (REAL C compilers do this with a structure assignment...)
  137.  *
  138.  */
  139. fdefault(hinfop)
  140. HINFO *hinfop;
  141. {
  142.     hinfop->hi_cc = deffmt.hi_cc;
  143.     hinfop->hi_dhc = deffmt.hi_dhc;
  144.     hinfop->hi_rwcc = deffmt.hi_rwcc;
  145.     hinfop->hi_wpc = deffmt.hi_wpc;
  146.     hinfop->hi_lz = deffmt.hi_lz;
  147.     hinfop->hi_rt = deffmt.hi_rt;
  148.     hinfop->hi_in = deffmt.hi_in;
  149.     hinfop->hi_spt = deffmt.hi_spt;
  150. }
  151.  
  152.  
  153. /*
  154.  * Set mode information on drive.
  155.  *
  156.  */
  157. ms(dev, hinfo)
  158. int dev;
  159. HINFO *hinfo;
  160. {
  161.     int i;
  162.     char *p;
  163.     SETMODE mb;
  164.     extern long mode_set();
  165.  
  166.     /* initialize parameter structure */
  167.     p = (char *)&mb;
  168.     for (i = sizeof(SETMODE); i--;)
  169.     *p++ = 0;
  170.     mb.smd_8 = 0x08;
  171.     mb.smd_1 = 0x01;
  172.     mb.smd_bs[1] = 0x02;    /* block size = 512 */
  173.  
  174.     cpw(&mb.smd_cc[0], hinfo->hi_cc);
  175.     mb.smd_dhc = hinfo->hi_dhc;
  176.     cpw(&mb.smd_rwc[0], hinfo->hi_rwcc);
  177.     cpw(&mb.smd_wpc[0], hinfo->hi_wpc);
  178.     mb.smd_lz = hinfo->hi_lz;
  179.     mb.smd_rt = hinfo->hi_rt;
  180.  
  181.     return (int)mode_set(dev, 22, &mb);
  182. }
  183.  
  184.  
  185. /*
  186.  * Move `w' to unaligned location.
  187.  *
  188.  */
  189. cpw(d, w)
  190. char *d;
  191. WORD w;
  192. {
  193.     char *s;
  194.  
  195.     s = (char *)&w;
  196.     d[0] = s[0];
  197.     d[1] = s[1];
  198. }
  199.  
  200.  
  201. /*
  202.  * Return format parameters in `hinfo', based on
  203.  * the format parameter name `fpnam'.
  204.  *
  205.  * return 0 on OK,
  206.  * -1 on [CANCEL].
  207.  *
  208.  */
  209. gfparm(modesel, hinfop, fpnam, id)
  210. int *modesel;
  211. HINFO *hinfop;
  212. char *fpnam, *id;
  213. {
  214.     long num;
  215.     char name[128];
  216.  
  217.     strcpy(name, fpnam);
  218.     if (wgetent(fpnam, id) == ERROR) {
  219.         nofmt[NOSCHFOK].ob_state = NORMAL;
  220.         (nofmt[NOSCHFMT].ob_spec)->te_ptext = name;
  221.         execform(nofmt);
  222.         return ERROR;
  223.     }
  224.  
  225.     fdefault(hinfop);
  226.     if (wgetnum("cy", &num) == OK) hinfop->hi_cc = (UWORD)num;
  227.     if (wgetnum("hd", &num) == OK) hinfop->hi_dhc = (BYTE)num;
  228.     if (wgetnum("rw", &num) == OK) hinfop->hi_rwcc = (UWORD)num;
  229.     if (wgetnum("wp", &num) == OK) hinfop->hi_wpc = (UWORD)num;
  230.     if (wgetnum("lz", &num) == OK) hinfop->hi_lz = (BYTE)num;
  231.     if (wgetnum("rt", &num) == OK) hinfop->hi_rt = (BYTE)num;
  232.     if (wgetnum("in", &num) == OK) hinfop->hi_in = (BYTE)num;
  233.     if (wgetnum("sp", &num) == OK) hinfop->hi_spt = (BYTE)num;
  234.     if (wgetnum("md", &num) == OK) *modesel = (UWORD)num;
  235.     return OK;
  236. }
  237.  
  238.  
  239. /*
  240.  *    Set mode information on a SYQUEST drive.
  241.  *
  242.  */
  243.  
  244. sqms(dev, sendata)
  245. int dev;            /* physical device number */
  246. char sendata[];
  247. {
  248.     extern long mode_set();
  249.  
  250.     sendata[0] = sendata[2] = 0;    /* reserved */
  251.     sendata[3] = 0x08;                /* block descriptor length */
  252.     sendata[12] = 0;                /* Reserved = 0; Page Code = 0 */
  253.     sendata[13] = 0x02;                
  254.     sendata[14] = 0x10;                /* set inhst bit in page 00 */
  255.     sendata[15] = 0;                /* Device type qualifier  */
  256.     return (int)mode_set(dev, 16, sendata);
  257. }
  258.  
  259.  
  260.